package servlet.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import servlet.bean.CourseBean;
import servlet.bean.TeacherBean;
import servlet.bean.UserBean;
import servlet.model.ServiceFactory;
import servlet.publicUtils.MyUtils;

public class StuInfoModifyServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//request.setCharacterEncoding("UTF-8");
		String strOperationType = request.getParameter("opt");
		int iOpt = MyUtils.ObjtoInt(strOperationType);
		String strJumpPage = "";
		//判断是否进入哪个界面
		if(iOpt==0){
			//删除重复数据
			ServiceFactory.getUserInfoManagerServiceInstance().delCouInfo();
			//打印所有课程
			List<CourseBean> lstCou=ServiceFactory.getUserInfoManagerServiceInstance().getCouInfo();
			request.getSession().setAttribute("lstCou", lstCou);
			//传课程id
			String strUid = request.getParameter("uid");
	
			CourseBean couB = (CourseBean) MyUtils.getNewInstance(CourseBean.class);
			//传学生id
			couB.setStu_id(request.getParameter("selectcou"));
			couB.setCou_name(request.getParameter("uname"));
			
			
			ServiceFactory.getUserInfoManagerServiceInstance().selectCou(couB,strUid);
			
				
			strJumpPage = "logined/stuSelectCourse.jsp";
			
			
		}
		if(iOpt==2){
			//查询
			TeacherBean teaB = (TeacherBean) MyUtils.getNewInstance(TeacherBean.class);
			
			teaB.setStu_id(request.getParameter("username"));
			
			
			//查询操作
			List<TeacherBean> lstStu2=ServiceFactory.getUserInfoManagerServiceInstance().queryStuInfo2(teaB);
			request.getSession().setAttribute("lstStu2", lstStu2);
			strJumpPage = "logined/stuInfoAddDetail.jsp";
			
		}
		
		// 跳转到修改页面
		request.getRequestDispatcher(strJumpPage).forward(request, response);
	}

}
